package com.sky.financelake.viewmodels.remote;

import android.util.Log;

import com.sky.financelake.bean.dto.CommunityDto;
import com.sky.financelake.bean.dto.CommunityDto1;
import com.sky.financelake.bean.entity.CommunityEntity;
import com.sky.financelake.bean.param.CommunityParam;
import com.sky.financelake.retrofit.ApiResponse;
import com.sky.financelake.retrofit.CommunityRepository;
import com.sky.financelake.ui.wigets.SingleLiveEvent;
import com.sky.financelake.viewmodels.BaseViewModel;

import java.util.List;

public class CommunityViewModel extends BaseViewModel {
    private SingleLiveEvent<ApiResponse<List<CommunityDto>>> pageLd;
    private SingleLiveEvent<ApiResponse<List<CommunityDto1>>> pageLd1;
    private SingleLiveEvent<ApiResponse<CommunityEntity>> detailLd;

    private CommunityRepository communityRepository;

    public CommunityViewModel() {
        communityRepository = CommunityRepository.getInstance();
    }

    public CommunityRepository getCommunityRepository() {
        return communityRepository;
    }

    public SingleLiveEvent<ApiResponse<List<CommunityDto>>> getPageLiveData() {
        if (pageLd == null) {
            pageLd = new SingleLiveEvent<ApiResponse<List<CommunityDto>>>();
        }
        return pageLd;
    }

    public SingleLiveEvent<ApiResponse<List<CommunityDto1>>> getPageLiveData1() {
        if (pageLd1 == null) {
            pageLd1 = new SingleLiveEvent<ApiResponse<List<CommunityDto1>>>();
        }
        return pageLd1;
    }

    public SingleLiveEvent<ApiResponse<CommunityEntity>> getDetailLiveData() {
        if (detailLd == null) {
            detailLd = new SingleLiveEvent<ApiResponse<CommunityEntity>>();
        }
        return detailLd;
    }


    public SingleLiveEvent<ApiResponse<List<CommunityDto>>> getCommunityPagingList(int type, int pageNo) {
        Log.i(TAG, "getCommunityPagingList: ");
        CommunityParam param = new CommunityParam();
        param.setType(type);
        param.setPageNo(pageNo);
        communityRepository.getCommunityPagingList(getPageLiveData(), param);
        return pageLd;
    }

    public SingleLiveEvent<ApiResponse<CommunityEntity>> getCommunityById(Integer id) {
        communityRepository.getCommunityById(getDetailLiveData(), id);
        return detailLd;
    }

    public SingleLiveEvent<ApiResponse<List<CommunityDto1>>> getCommunityPagingList1(int type, int pageNo) {
        Log.i(TAG, "getCommunityPagingList: ");
        CommunityParam param = new CommunityParam();
        param.setType(type);
        param.setPageNo(pageNo);
        communityRepository.getCommunityPagingList1(getPageLiveData1(), param);
        return pageLd1;
    }
}
